package org.cxy.monitor;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

@Configuration
@EnableConfigurationProperties(MonitorProperties.class)
@EnableAspectJAutoProxy
// 条件化控制 Bean 的创建，只有当配置文件中 monitor.enabled=true 时，才会创建 MonitorAutoConfiguration 类
@ConditionalOnProperty(prefix = "monitor", name = "enabled", havingValue = "true", matchIfMissing = true)
public class MonitorAutoConfiguration {

    @Bean
    public MonitorService monitorService() {
        return new MonitorService();
    }

    @Bean
    public MonitorAspect monitorAspect() {
        return new MonitorAspect();
    }
}